<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户管理</title>
</head>
<body>
<div id="master">
    <table border="1" cellspacing="0">
        <thead>
        <tr align="center" height="40">
            <th width="300">用户名</th>
            <th width="300">邮箱</th>
            <th width="100">用户身份</th>
            <th width="150">是否封禁</th>
        </tr>
        </thead>
        <tr v-for="user in users"height="40">
            <td>{{user.name}}</td>
            <td>{{user.email}}</td>
            <td>{{user.identity}}</td>
            <td>{{user.status}}</td>
            <td>
                <form>
                    <input type="button" value="封禁" :name="user.id" onclick="ban_click(this.name)">
                </form>
            </td>
        </tr>
    </table>
    <div align="center">
        <input type="button" value="上一页" onclick="up_click()"></input>
        <input type="button" value="下一页" onclick="down_click()"></input>
    </div>
</div>
</body>
</html>

<script src="../js/ajax.js"></script>
<script src="../js/vue.js"></script>

<script>
    window.onload=function getData() {
        let currentPage=window.localStorage.getItem("page");
        new Vue({
            el: "#master",
            data() {
                return {
                    users: []
                }
            },
            mounted() {
                let _this = this;
                ajax({
                    method: "post",
                    url: "../../master",
                    data: {
                        currentPage:currentPage,
                        code: 0
                    },
                    success: function (result) {
                        console.log(result);
                        _this.users = result;
                    },
                    error: function (result) {
                        console.log(result);
                    }
                })
            }
        })
    }

    function ban_click(e) {
        console.log(e)
        ajax({
            method: "post",
            url: "../../master",
            data: {
                userId:e,
                code: 1
            },
            success: function (result) {
                alert("操作成功");
                console.log(result);
            },
            error: function (result) {
                console.log(result);
            }
        })
    }

    function up_click(){
        let currentPage=window.localStorage.getItem("page");
        currentPage=currentPage-1;
        window.localStorage.setItem("page",currentPage.toString());
        window.location.href="./masterUser.html";
    }

    function down_click(){
        let currentPage=window.localStorage.getItem("page");
        currentPage=parseInt(currentPage)+1;
        window.localStorage.setItem("page",currentPage.toString());
        window.location.href="./masterUser.html";
    }
</script>